<template>
  <div class="project-audit-list-view">

    <modules-title class="title-position" titleName="待我审核">

      <template slot="btn">
      </template>

    </modules-title>

    <div class="content">

      <el-table v-loading="loading" border size="medium" :data="tableData" @row-click="tableRowClick">
        <el-table-column label="流程编号" align="center" prop="SerialNumber" width="120" />
        <el-table-column label="业务类型" align="center" width="140">
          <template slot-scope="scope">
            <span v-if="scope.row.TemplateType == 'QualitySource'">质量标准审批</span>
            <span v-else-if="scope.row.TemplateType == 'StabilityScheme'">稳定性方案审批</span>
            <span v-else-if="scope.row.TemplateType == 'ExchangeStability'">更换稳定性箱审批</span>
            <span v-else-if="scope.row.TemplateType == 'BuildProject'">立项审批</span>
            <span v-else-if="scope.row.TemplateType == 'Resolutions'">立项决议审批</span>
            <span v-else-if="scope.row.TemplateType == 'CheckResult'">检验结果审批</span>
            <span v-else-if="scope.row.TemplateType == 'RepealCheck'">撤销检验审批</span>
            <span v-else-if="scope.row.TemplateType == 'ApprovalCheck'">请验审批</span>
            <span v-else-if="scope.row.TemplateType == 'RetainDestroy'">留样销毁审批</span>
            <span v-else-if="scope.row.TemplateType == 'ProblemAcceptance'">问题验收</span>
            <span v-else-if="scope.row.TemplateType == 'ChangeProjectInfo'">项目信息变更</span>
            <span v-else-if="scope.row.TemplateType == 'ChangeProjectMember'">项目成员变更</span>
            <span v-else-if="scope.row.TemplateType == 'ChangeProjectTask'">项目任务变更</span>
            <span v-else-if="scope.row.TemplateType == 'ProjectPause'">项目暂停</span>
            <span v-else-if="scope.row.TemplateType == 'ProjectStop'">项目终止</span>
            <span v-else-if="scope.row.TemplateType == 'ProjectFirstCheck'">项目方案书</span>
            <span v-else-if="scope.row.TemplateType == 'ProjectPlanCheck'">项目项目计划</span>
            <span v-else-if="scope.row.TemplateType == 'ProjectEndCheck'">项目结题验收</span>
            <span v-else-if="scope.row.TemplateType == 'TaskCheck'">任务验收</span>
          </template>
        </el-table-column>
<!--        <el-table-column label="申请人" align="center" width="140">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="scope.row.Creator">{{scope.row.Creator.name}}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="信息摘要" align="center" prop="project_name" >
          <template slot-scope="scope">
            <span v-if="scope.row.Template">{{scope.row.Template.Abstract}}</span>
          </template>
        </el-table-column>
        <el-table-column label="发起时间" align="center" prop="CreatedAt" >
          <template slot-scope="scope">
            <span>{{scope.row.CreatedAt ? dateFormat1("yyyy-mm-dd",scope.row.CreatedAt) : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column label="最后处理时间" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.CreatedAt ? dateFormat1("yyyy-mm-dd",scope.row.CreatedAt) : ""}}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" width="125">
          <template slot-scope="scope">
            <span v-if="scope.row.State == 'ToDo'">待审核</span>
            <span v-else-if="scope.row.State == 'Doing'">审核中</span>
            <span v-else-if="scope.row.State == 'Reject'">驳回上一步</span>
            <span v-else-if="scope.row.State == 'Refuse'">已拒绝</span>
            <span v-else-if="scope.row.State == 'Done'">审核完成</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="350">
          <template slot-scope="scope">

            <el-button
              v-if="scope.row.State != 'Done' || scope.row.State != 'Refuse'"
              size="medium"
              type="text"
              icon="el-icon-order"
              @click="auditClick(scope.row.Id)">
              审批申请
            </el-button>

          </template>
        </el-table-column>
      </el-table>

    </div>

    <el-dialog
      title="审批申请"
      :visible.sync="dialogVisible"
      width="800px"
      :before-close="handleClose">

<!--      <audit-apply-view ref="auditView"></audit-apply-view>-->

      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogConfirm">确 定</el-button>
        </span>
    </el-dialog>

  </div>
</template>

<script>
    export default {
        name: "index",
        data:function () {
            return{
                loading:false,
                pageSize:10,
                pageNum:1,
                total:0,
                dialogVisible:false,
                tableData:[],

            }
        },
        mounted:function() {
            this.getListData()
        },
        methods:{
            tableRowClick:function(row, column, event){

                // if (column.label != '操作'){
                //     this.$router.push({name:'projectManagementReportDetail',query:{id:row.id}});
                // }
                this.$router.push({name:'projectAuditDetail',query:{id:row.Id}});
            },
            handleClose:function () {
                this.dialogVisible = false;
            },
            dialogConfirm:function () {
                this.dialogVisible = true;
                if (this.$refs.auditView){

                    this.$api.PROJECT_WORK_APPLY_UPDATE(this.$refs.auditView.datas).then(res=>{
                        if (res.code == 200){
                            this.getListData();
                        }else{
                            this.$message.error(res.msg)
                        }
                    }).catch(err=>{

                    })
                }


            },
            getListData:function () {
                let data = {
                    pager:{
                        limit:this.pageSize,
                        skip:this.pageNum,
                    }
                }
                this.loading = true;
                this.$api.PROJECT_START_CHECK_LIST(data).then(res=>{
                    this.loading = false;
                    if (res.code == 200){
                        this.tableData = res.data.data;
                        this.total = res.data.total;
                    }else{
                        this.$message.error(res.msg)
                    }
                }).catch(err=>{
                    this.loading = false;
                })
            },
            auditClick:function (id) {
                let index = this.tableData.findIndex(a=>a.id == id)
                if (index != -1){
                    let data = this.tableData[index];
                    this.dialogVisible = true;
                    setTimeout(() => {
                        if (this.$refs.auditView){
                            this.$refs.auditView.setData(data);
                        }
                    },500)

                }
            },
            detailClick:function (id) {

            }
        }
    }
</script>

<style lang="scss" scoped>
  @import "../../../assets/scss/views/projectManagement/audit/list.scss";
</style>
